package com.jack.vipmis.vip.wei.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.jack.vipmis.common.entity.search.SearchOperator;
import com.jack.vipmis.common.entity.search.Searchable;
import com.jack.vipmis.common.service.BaseService;
import com.jack.vipmis.vip.wei.entity.Circle;
import com.jack.vipmis.vip.wei.repository.CircleRepository;

/**
 * 
 * @author JackLiang
 * @date 2014-7-2
 * @version 1.0
 */
@Service
public class CircleService extends BaseService<Circle, Long> {

	private CircleRepository getCircleRepository() {
		return (CircleRepository) baseRepository;
	}

	/**
	 * 分页查询
	 * 
	 * @param page
	 * @param pageSize
	 * @param type
	 * @return
	 */
	public Page<Circle> getCircleByPage(int page, int pageSize, long type) {
		Searchable searchable = buildSearchable(page, pageSize, type);
		return getCircleRepository().findAll(searchable);
	}

	/**
	 * 构建查询条件
	 * 
	 * @param page
	 * @param pageSize
	 * @param type
	 * @return
	 */
	private Searchable buildSearchable(int page, int pageSize, long Category) {
		Searchable searchable = Searchable.newSearchable();
		searchable.addSearchFilter("Category", SearchOperator.eq, Category);
		searchable.addSort(Direction.DESC, "postCreateTime");
		searchable.setPage((page - 1), pageSize);
		return searchable;
	}
}
